//
//  ECUITVCell_CourseList.m
//  Edu_iOS2018
//
//  Created by yanyan on 2018/1/6.
//  Copyright © 2018年 yanyan. All rights reserved.
//

#import "ECUITVCell_CourseList.h"
#import "ECFormatHelper.h"
#import "CourseModel.h"
@interface ECUITVCell_CourseList()
@property(nonatomic,strong)UIImageView *logoView;
@property(nonatomic,strong)UILabel *titleLabel;//名字

@property(nonatomic,strong)UILabel *studyNumLabel;//多少人在学
@property(nonatomic,strong)UILabel *priceLabel;//价格
@end
@implementation ECUITVCell_CourseList

- (void)addSubviews
{
    [super addSubviews];
    self.logoView = [[UIImageView alloc]init];
    [self.logoView setShowActivityIndicatorView:YES];
    [self.logoView setIndicatorStyle:UIActivityIndicatorViewStyleGray];
    self.logoView.userInteractionEnabled = NO;
    self.logoView.backgroundColor = [UIColor whiteColor];
    self.logoView.contentMode = UIViewContentModeScaleAspectFill;
    self.logoView.layer.cornerRadius = 5;
    self.logoView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.logoView];
    _titleLabel = [[UILabel alloc]init];
    _titleLabel.font = [UIFont systemFontOfSize:13*kPercentage];
    _titleLabel.textColor = [UIColor colorWithHexString:@"#000000"];
    _titleLabel.numberOfLines = 1;
    [self.contentView addSubview:_titleLabel];
    _studyNumLabel = [[UILabel alloc]init];
    _studyNumLabel.font = [UIFont systemFontOfSize:12];
    _studyNumLabel.textColor = [UIColor colorWithHexString:@"#808080"];
    [self.contentView addSubview:_studyNumLabel];
    
    _priceLabel = [[UILabel alloc]init];
    _priceLabel.font = [UIFont systemFontOfSize:14];
    _priceLabel.textColor = [UIColor colorWithHexString:@"#ef4023"];
    [self.contentView addSubview:_priceLabel];
    WeakSelf(weakSelf);
    CGFloat padding = 8;
    [self.logoView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(weakSelf.contentView).offset(17 * kPercentage);
        make.left.equalTo(weakSelf.contentView).offset(padding);
        make.width.equalTo(@(kProportion_Width(324)));
        make.height.equalTo(weakSelf.logoView.mas_width).multipliedBy(0.5);
        make.centerY.equalTo(weakSelf.contentView);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.logoView.mas_top);
        make.left.equalTo(weakSelf.logoView.mas_right).offset(padding);
        make.right.equalTo(weakSelf.contentView).offset(-5);
    }];
    [self.studyNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.greaterThanOrEqualTo(self.titleLabel.mas_bottom);
        make.left.equalTo(weakSelf.titleLabel);
//        make.right.lessThanOrEqualTo(weakSelf.contentView);
        make.centerY.equalTo(weakSelf.contentView);
        make.right.equalTo(self.titleLabel);
    }];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.studyNumLabel.mas_bottom).offset(5);
        make.left.equalTo(weakSelf.titleLabel);
//        make.right.lessThanOrEqualTo(weakSelf.contentView);
        make.bottom.equalTo(weakSelf.logoView);
        make.right.equalTo(self.titleLabel);

    }];
    
    
}
- (void)setObject:(id)object
{
    [super setObject:object];
    CourseModel *mo = object;
    [self.logoView sd_setImageWithURL:[NSURL URLWithString:mo.pictureUrl] placeholderImage:nil];
    [self.titleLabel setText:mo.title];
    self.studyNumLabel.text = [NSString stringWithFormat:@"%@人在学",mo.num];
    self.priceLabel.attributedText = [ECFormatHelper attributedStringForPromotionPrice:mo.price decimal:2 smallFontSize:10];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
